<template>
  <a-form
    ref="form"
    layout="inline"
    :model="model"
    :rules="rules"
    :label-width="labelWidth"
    :label-position="position"
    class="form-block"
  >
    <slot />
  </a-form>
</template>
<script>
export default {
  name: 'FormBlock',
  props: {
    model: {
      type: Object,
      default: () => {}
    },
    rules: {
      type: Object,
      default: () => {}
    },
    labelWidth: {
      type: String,
      default: ''
    },
    inline: {
      type: Boolean,
      default: true
    },
    position: {
      type: String,
      default: 'right'
    }
  },
  methods: {
    // 验证
    validate() {
      return new Promise((resolve, reject) => {
        this.form.validate(valid => {
          if (valid) {
            resolve(true);
          } else {
            resolve(false);
          }
        });
      });
    },
    // 重置
    resetForm() {
      this.form.resetFields();
    }
  }
};
</script>
